//
//  ViewController.m
//  DLAddToDesktop
//
//  Created by donglei on 16/4/1.
//  Copyright © 2016年 DL. All rights reserved.
//

#import "ViewController.h"
#import "DLAddToDesktopHandler.h"
#import "UIImage+DLDataURIImage.h"
#import "DLBase64.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController




- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *douyin1 = [[UIImage imageNamed:@"douyin"] dataURISchemeImage];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)addToDesktop:(id)sender {
    
   DLAddToDesktopHandler *handler = [DLAddToDesktopHandler sharedInsance];
    NSString *imageString = [[UIImage imageNamed:@"webIcon"] dataURISchemeImage];
    [handler addToDesktopWithDataURISchemeImage:imageString
                                          title:@"weixinTitle"
                                      urlScheme:@"weixin"
                                 appDownloadUrl:@"https://itunes.apple.com/cn/app/id414478124?mt=8"];
    
    // DLAddToDesktop   @"DLAddToDesktop://para=a"

}
- (IBAction)addAnotherOne:(id)sender {
    
    DLAddToDesktopHandler *handler = [DLAddToDesktopHandler sharedInsance];
    NSString *imageString = [[UIImage imageNamed:@"webIcon1"] dataURISchemeImage];
    [handler addToDesktopWithDataURISchemeImage:imageString
                                          title:@"Donglei"
                                      urlScheme:@"DLAddToDesktop://"
                                 appDownloadUrl:@"https://appsto.re/cn/S8gTy.i"];
}

- (IBAction)click:(id)sender {
    //    NSURL *url = [NSURL URLWithString:@"http://47.74.52.226:8010/content.html"];
//    NSURL *url = [NSURL URLWithString:@"http://192.168.135.43/weixin.html"];
//    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/weixin.html?link=weixin"];
//    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/weixin.html"];
    
    NSString *htmlContent = [self readLocalHtmlContent:@"index.html"];
    htmlContent = [NSString stringWithFormat:@"data:text/html;charset=utf-8,%@", htmlContent];
    // 编码
    htmlContent = [htmlContent stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *urlString = @"http://192.168.135.43/weixin.html?dataurl=";
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlString, htmlContent]];
    [[UIApplication sharedApplication] openURL:url];
}


- (NSString *)readLocalHtmlContent:(NSString *)fileName {
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
    NSString *htmlContent = [NSString stringWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:htmlPath] encoding:NSUTF8StringEncoding error:nil];
    return htmlContent;
}

@end
